package com.bright.ghj.stats.util;

import com.bright.ghj.stats.pojo.po.second.User;

import java.util.Objects;

/**
 * @Author txf
 * @Date 2022/7/27 15:47
 * @Description
 */
public class SecurityUtil {

    public static User getLoginUser() {
        return getLoginUser(true);
    }

    public static User getLoginUser(boolean isCheckTableType) {
//        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//        SecurityUser securityUser = null;
//        if ("anonymousUser".equals(principal.toString())) {
////            securityUser = new SecurityUser();
////            User user = new User();
////            user.setUsername("超级用户");
////            user.setTjDistNo("01");
////            List<Dist> dists = new ArrayList<>();
////            user.setDistNo("01");
////            user.setDistName("广州市");
////            user.setDists(dists);
////            TableType tableType = new TableType();
////            tableType.setTableType("年报(政改处)");
////            tableType.setOptType(1);
////            user.setTableType(tableType);
////            securityUser.setUser(user);
//
//        } else {
//            securityUser = (SecurityUser) principal;
//            User user = securityUser.getUser();
//            if(!Objects.isNull(user) && StringUtils.isBlank(user.getTjDistNo())){
//                user.setTjDistNo(user.getDistNo());
//            }
////            User user = securityUser.getUser();
////            TableType tableType = new TableType();
////            tableType.setTableType("年报(政改处)");
////            tableType.setOptType(1);
////            user.setTableType(tableType);
////            securityUser.setUser(user);
//        }

        User user = com.bright.ghj.user.util.SecurityUtil.getLoginUser();

        if(isCheckTableType && (Objects.isNull(user) || Objects.isNull(user.getTableType()))){
            throw new RuntimeException("当前用户未选择模式");
        }


        return user;
    }
}
